/*Copyright (C) 2009 - 2011 MASSART GAUTHIER

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "../headers.h"

void bienvenue_1(const char *maj) {

	if(animations_bienvenue_fin) {
		short i = 0, z = 14, x = 0, y = 0;
		CSLP_Sleep(250);
		attroff(A_BOLD);
		CSLP_ColorText(COLOR_BLACK);

		mvaddstr(14, x_begin_center(49), "*************************************************");
		mvaddstr(15, x_begin_center(49), "*                                               *");
		mvaddstr(16, x_begin_center(49), "*                   BIENVENUE                   *");
		mvaddstr(17, x_begin_center(49), "*           DANS LES JEUX INDEMODABLES          *");
		mvaddstr(18, x_begin_center(49), "*                                               *");
		mvprintw(19, x_begin_center(49), "*                 VERSION %s                *", version_jeu);
		mvaddstr(20, x_begin_center(49), "*      CREE PAR GAUTHIER, BMAUET ET MIRCKO      *");
		mvaddstr(21, x_begin_center(49), "*                                               *");
		mvaddstr(22, x_begin_center(49), "*************************************************");
		attron(A_BOLD);
		balayage_horizontal();
		CSLP_Sleep(150);
		balayage_vertical();
		i = 0;

		while(i != 4) {
			while(x != 23) {
				while(y != DEFAULT_SCREEN_SIZE_X) {
					y++;
					couleur_flash_2(x, y);
				}

				x++;
				y = 0;
			}

			refresh();
			CSLP_Sleep(250);
			x = 0, y = 0;

			while(x != 23) {
				while(y != DEFAULT_SCREEN_SIZE_X) {
					y++;
					couleur_flash_1(x, y);
				}

				x++;
				y = 0;
			}

			refresh();
			CSLP_Sleep(250);
			x = 0, y = 0;
			i++;
		}

		while(z != 0) {

			CSLP_ColorText(COLOR_CYAN);
			mvaddstr(z    , x_begin_center(49), "*************************************************");
			mvaddstr(z + 1, x_begin_center(49), "*                                               *");
			mvaddstr(z + 2, x_begin_center(49), "*");
			CSLP_ColorText(COLOR_YELLOW);
			addstr("                   BIENVENUE                   ");
			CSLP_ColorText(COLOR_CYAN);
			addstr("*");
			mvaddstr(z + 3, x_begin_center(49), "*");
			CSLP_ColorText(COLOR_YELLOW);
			addstr("           DANS LES JEUX INDEMODABLES          ");
			CSLP_ColorText(COLOR_CYAN);
			addstr("*");
			mvaddstr(z + 4, x_begin_center(49), "*                                               *");
			mvaddstr(z + 5, x_begin_center(49), "*");
			CSLP_ColorText(COLOR_MAGENTA);
			printw("                 VERSION %s                ", version_jeu);
			CSLP_ColorText(COLOR_CYAN);
			addch('*');
			mvaddstr(z + 6, x_begin_center(49), "*");
			CSLP_ColorText(COLOR_MAGENTA);
			addstr("      CREE PAR GAUTHIER, BMAUET ET MIRCKO      ");
			CSLP_ColorText(COLOR_CYAN);
			addch('*');
			mvaddstr(z + 7, x_begin_center(49), "*                                               *");
			mvaddstr(z + 8, x_begin_center(49), "*************************************************");
			mvaddstr(z + 9, x_begin_center(49), "                                                 ");
			z -= 1;
			refresh();
			CSLP_Sleep(20);
		}

		if(maj != NULL) {
			char **list_maj = split("$", maj);
			CSLP_ColorText(CT);
			mvaddstr(0, x_begin_center(115), "MISE A JOUR DISPONIBLE !");
			mvaddstr(1, x_begin_center(115), "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯");
			for(i = 0; list_maj[i] != NULL; i++) {
				mvaddstr(2 + i, 0, list_maj[i]);
			}
			unsplit(list_maj);
		}

		CSLP_ColorText(COLOR_BLUE);
		mvaddstr(0, x_begin_center(49), "*************************************************");
		mvaddstr(1, x_begin_center(49), "*                                               *");
		mvaddstr(2, x_begin_center(49), "*");
		CSLP_ColorText(COLOR_GREEN);
		addstr("                   BIENVENUE                   ");
		CSLP_ColorText(COLOR_BLUE);
		addch('*');
		mvaddstr(3, x_begin_center(49), "*");
		CSLP_ColorText(COLOR_GREEN);
		addstr("           DANS LES JEUX INDEMODABLES          ");
		CSLP_ColorText(COLOR_BLUE);
		addch('*');
		mvaddstr(4, x_begin_center(49), "*                                               *");
		mvaddstr(5, x_begin_center(49), "*");
		CSLP_ColorText(COLOR_RED);
		printw("                 VERSION %s                ", version_jeu);
		CSLP_ColorText(COLOR_BLUE);
		addch('*');
		mvaddstr(6, x_begin_center(49), "*");
		CSLP_ColorText(COLOR_RED);
		addstr("      CREE PAR GAUTHIER, BMAUET ET MIRCKO      ");
		CSLP_ColorText(COLOR_BLUE);
		addch('*');
		mvaddstr(7, x_begin_center(49), "*                                               *");
		mvaddstr(8, x_begin_center(49), "*************************************************\n");
	}
}

void verif_caractere_xy_1(short x, short y) {
	if((x == 14 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || (x == 22 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || ((x >= 15 && x <= 22) && (y == x_begin_center(49) || y == x_begin_center(49) + 48)))
		mvchgat(x, y, 1, A_NORMAL, CSLP_GetPair(COLOR_WHITE, COLOR_WHITE), NULL);
	else if((x == 16 || x == 17) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_GREEN, COLOR_WHITE), NULL);
	else if((x == 19 || x == 20) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_RED, COLOR_WHITE), NULL);
	else
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_BLACK, COLOR_WHITE), NULL);
}
void verif_caractere_xy_2(short x, short y) {
	if((x == 14 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || (x == 22 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || ((x >= 15 && x <= 22) && (y == x_begin_center(49) || y == x_begin_center(49) + 48)))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_BLUE, COLOR_BLACK), NULL);
	else if((x == 16 || x == 17) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_GREEN, COLOR_BLACK), NULL);
	else if((x == 19 || x == 20) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_RED, COLOR_BLACK), NULL);
	else
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_BLACK, COLOR_BLACK), NULL);
}
void couleur_flash_1(short x, short y) {
	if((x == 14 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || (x == 22 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || ((x >= 15 && x <= 22) && (y == x_begin_center(49) || y == x_begin_center(49) + 48)))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_BLUE, COLOR_BLACK), NULL);
	else if((x == 16 || x == 17) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_GREEN, COLOR_BLACK), NULL);
	else if((x == 19 || x == 20) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_RED, COLOR_BLACK), NULL);
	else
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_BLACK, COLOR_BLACK), NULL);
}
void couleur_flash_2(short x, short y) {
	if((x == 14 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || (x == 22 && (y >= x_begin_center(49) && y <= x_begin_center(49) + 48)) || ((x >= 15 && x <= 22) && (y == x_begin_center(49) || y == x_begin_center(49) + 48)))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_CYAN, COLOR_BLACK), NULL);
	else if((x == 16 || x == 17) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_YELLOW, COLOR_BLACK), NULL);
	else if((x == 19 || x == 20) && (y >= x_begin_center(48) && y <= x_begin_center(48) + 46))
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_MAGENTA, COLOR_BLACK), NULL);
	else
		mvchgat(x, y, 1, A_BOLD, CSLP_GetPair(COLOR_BLACK, COLOR_BLACK), NULL);
}
void bienvenue_2(void) {
	short x = 0, y = 0, caractere = 1;

	while(x != 8) {
		while(y < DEFAULT_SCREEN_SIZE_X) {
			if(caractere == 1) {
				CSLP_Color(COLOR_BLACK, COLOR_BLACK);
				mvaddstr(x, y, "♠");
			}
			else if(caractere == 2) {
				CSLP_Color(COLOR_RED, COLOR_BLACK);
				mvaddstr(x, y, "♥");
			}
			else if(caractere == 3) {
				CSLP_Color(COLOR_GREEN, COLOR_BLACK);
				mvaddstr(x, y, "♣");
			}
			else if(caractere == 4) {
				CSLP_Color(COLOR_RED, COLOR_BLACK);
				mvaddstr(x, y, "♦");
			}
			else if(caractere == 5) {
				CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
				mvaddstr(x, y, "☺");
				caractere = 0;
			}

			caractere++;
			y += 3;
		}

		x++;
		y = 0;

		if(x < 5) {
			caractere = x + 1;
		}
		else {
			caractere = x - 4;
		}
	}

	CSLP_ColorText(COLOR_BLUE);
	mvaddstr(2, x_begin_center(44), "┌──────────────────────────────────────────┐");
	mvaddstr(3, x_begin_center(44), "│");
	CSLP_ColorText(COLOR_WHITE);
	printw("   Les jeux indémodables version %s   ", version_jeu);
	CSLP_ColorText(COLOR_BLUE);
	addstr("│");
	CSLP_ColorText(COLOR_BLUE);
	mvaddstr(4, x_begin_center(44), "└──────────────────────────────────────────┘");
	move(7, 0);
	refresh();
}

void balayage_horizontal(void) {
	short boucle1 = 0, boucle2 = 0, x = 0, y = 0, a = 1, b = DEFAULT_SCREEN_SIZE_X - 1;

	CSLP_ColorText(COLOR_WHITE);

	while(boucle2 != DEFAULT_SCREEN_SIZE_X) {
		while(boucle1 != 20) {

			verif_caractere_xy_1(x, y);
			x += 2;

			verif_caractere_xy_1(a, b);
			a += 2;

			boucle1++;
		}

		x = 0, a = 1;

		y++;
		b--;
		boucle2++;
		boucle1 = 0;
		refresh();
		CSLP_Sleep(15);
	}
}

void balayage_vertical(void) {
	short boucle1 = 0, boucle2 = 0, x = 0, y = 0, a = 39, b = 1;

	CSLP_ColorText(COLOR_BLACK);

	while(boucle2 != 40) {
		while(boucle1 != DEFAULT_SCREEN_SIZE_X / 2) {
			verif_caractere_xy_2(x, y);
			y += 2;

			verif_caractere_xy_2(a, b);
			b += 2;

			boucle1++;
		}

		y = 0, b = 1;

		a--;
		x++;
		boucle2++;
		boucle1 = 0;
		refresh();
		CSLP_Sleep(30);
	}

	move(0, 0);
}
